package me.spring.cloud.common.components.elasticjob.lite.util;

import java.util.List;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.util.StringUtils;

/**
 * @author luffy
 * @description: BeanDefinition 构造
 * @date 2019-03-27 10:26
 */
public class BeanDefinitionUtil {
  public static List<BeanDefinition> getBeanDefinitions(List<BeanDefinition> result, String distributedListeners,
      long startedTimeoutMilliseconds, long completedTimeoutMilliseconds) {
    if (StringUtils.hasText(distributedListeners)) {
      BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(distributedListeners);
      factory.setScope(BeanDefinition.SCOPE_PROTOTYPE);
      factory.addConstructorArgValue(startedTimeoutMilliseconds);
      factory.addConstructorArgValue(completedTimeoutMilliseconds);
      result.add(factory.getBeanDefinition());
    }
    return result;
  }
}
